<?php

class OrderAction extends BusinessAction {

    public function hzOrder(){
    	$maps = array();
    	if($_REQUEST['order_num']){
    		$map['hx_order.order_num'] = array('like','%'.$_REQUEST['order_num'].'%');
    		$maps['order_num'] = $_REQUEST['order_num'];
    	}
    	if($_REQUEST['name']){
    		$map['hx_user.username'] = array('like','%'.$_REQUEST['name'].'%');
    		$maps['name'] = $_REQUEST['name'];
    	}
    	if($_REQUEST['type']){
    		$maps['type'] = $_REQUEST['type'];
    	}
    	if($_REQUEST['type']==1){
    		$map['hx_order.pay_type'] = 0;
    	}elseif($_REQUEST['type']==2){
    		$map['hx_order.pay_type'] = array('gt',0);
    	}elseif($_REQUEST['type']==3){
    		$map['hx_order.status'] = 60;
    	}
    	$map['hx_order.order_name'] = array('neq','');
        $map['hx_order.wx_id']=array("in",implode(",",C("officeShop")));   //杭州地区
    	$Data = M('order'); // 实例化Data数据对象
    	import("@.ORG.Page");// 导入分页类
    	$count = $Data->where($map)->count();// 查询满足要求的总记录数
    	$Page = new Page($count,20);// 实例化分页类 传入总记录数
    	foreach($maps as $key=>$val) {
    		$Page->parameter   .=   "$key=".urlencode($val).'&';
    	}
    	
    	$nowPage = isset($_GET['p'])?$_GET['p']:1;//当前页码
    	$list = $Data->join('hx_user on hx_order.user_id=hx_user.user_id')->join('hx_auto_model on hx_order.model_id=hx_auto_model.model_id')->field("hx_order.*,hx_user.username,hx_user.realname,hx_user.sex,hx_auto_model.*")->where($map)->page($nowPage.','.$Page->listRows)->order('hx_order.create_time desc')->select();

    	$show = $Page->show();// 分页显示输出
    	$this->assign('page',$show);// 赋值分页输出
    	$this->assign('list',$list);// 赋值数据集
    	$this->display(); // 输出模板
    }
    
    
    public function shOrder(){
    	$maps = array();
    	if($_REQUEST['order_num']){
    		$map['hx_order.order_num'] = array('like','%'.$_REQUEST['order_num'].'%');
    		$maps['order_num'] = $_REQUEST['order_num'];
    	}
    	if($_REQUEST['name']){
    		$map['hx_user.username'] = array('like','%'.$_REQUEST['name'].'%');
    		$maps['name'] = $_REQUEST['name'];
    	}
    	$map['hx_order.order_name'] = array('neq','');
        $map['hx_order.wx_id']=array("not in",implode(",",C("officeShop")));   //杭州地区
    	$Data = M('order'); // 实例化Data数据对象
    	import("@.ORG.Page");// 导入分页类
    	$count = $Data->where($map)->count();// 查询满足要求的总记录数
    	$Page = new Page($count,20);// 实例化分页类 传入总记录数.
    	foreach($maps as $key=>$val) {
    		$Page->parameter   .=   "$key=".urlencode($val).'&';
    	}
    	 
    	$nowPage = isset($_GET['p'])?$_GET['p']:1;//当前页码
    	$list = $Data->join('hx_user on hx_order.user_id=hx_user.user_id')->join('hx_auto_model on hx_order.model_id=hx_auto_model.model_id')->field("hx_order.*,hx_user.username,hx_user.realname,hx_auto_model.*")->where($map)->page($nowPage.','.$Page->listRows)->order('hx_order.create_time desc')->select();
    	
    	$show = $Page->show();// 分页显示输出
    	$this->assign('page',$show);// 赋值分页输出
    	$this->assign('list',$list);// 赋值数据集
    	$this->display(); // 输出模板
    }
    
    //订单详情
    public function orderInfo(){
    	$O = M('order');
    	$order_id = $_REQUEST['order_id'];
    	$order = $O->join('hx_user on hx_order.user_id=hx_user.user_id')->join('hx_user_auto ua on hx_order.ua_id=ua.ua_id')->join('hx_auto_model m on hx_order.model_id=m.model_id')->field('hx_order.*,hx_user.username,ua.vin,ua.number,m.*')->where("order_id=$order_id")->find();
    	
    	$I = M('order_info');
    	$orderInfo = $I->where('order_id='.$order_id)->select();
    	
    	$orderAdj = M('order_adj')->where('order_id='.$order_id)->select();
    	$this->assign('order',$order);
    	$this->assign('orderInfo',$orderInfo);
    	$this->assign('orderAdj',$orderAdj);
    	$this->display();
    }
    
    //空调清洗价格调整
    public function summer(){

        $map['hx_order.type'] = 10;
        $map['hx_order.status']=array("in","50,60");
        $map['all_price']=array("neq",'');
        $map['hx_order.privilege']="";
        $map['hx_order.order_name'] = array('neq','');
        $map['hx_order.wx_id']=array("in",implode(",",C("officeShop")));   //杭州地区

        import("@.ORG.Page");
        $O=M("order");
        $count = $O->where($map)->count();
        $p = new Page($count, 20);

        $list = $O->where($map)->join('hx_user on hx_order.user_id=hx_user.user_id')->join('hx_auto_model on hx_order.model_id=hx_auto_model.model_id')->limit($p->firstRow . ',' . $p->listRows)->order('hx_order.create_time desc')->select();
        $page = $p->show();
        $this->assign('page', $page);
        $this->assign('list',$list);
        $this->display();

    }

    //修改空调清洗价格
    public function editSummerOrder(){
        $map['order_id']=$_POST['id'];
        $O=M("order");
        $data['privilege']="分享立减224元";
        $data['order_num']=time().rand(100, 999);
        $data['all_price']=1;
        $res=$O->where($map)->save($data);
        if($res){
            $this->ajaxReturn($res,"设置成功",1);
        }else{
            $this->ajaxReturn(false,"设置失败",0);
        }
    }

    //订单详情
    public function time(){
    	$data = array();
    	$data['order_id'] = $_REQUEST['order_id'];
    	$data['yy_date'] = strtotime($_REQUEST['yy_date']);
    	$data['yy_time'] = $_REQUEST['yy_time'];
    	$res = M('order')->save($data);
    	echo $res;
    }

    //发送短信
    public function sendMsg(){
    	$this->display();
    }

    //发送短信
    public function send(){
    	if($_REQUEST['tel'] && $_REQUEST['con']){
    		if (!preg_match("/^(13|15|18|14|17)[0-9]{9}$/", $_REQUEST['tel'])) {
    			$this->error('手机号不正确',U('Order/sendMsg'));
    		}
    		import("@.ORG.MobileSms");
    		$mobilesms = new MobileSms();
    		$sms['to_phone'] = $_REQUEST['tel'];
    		$sms['content'] = $_REQUEST['con'];
    		 
    		$rs = $mobilesms->send($sms['to_phone'], $sms['content']);
    		$this->success('发送成功',U('Order/sendMsg'));
    	}else{
    		$this->error('手机号或发送内容不能为空',U('Order/sendMsg'));
    	}
    }  

    //发送短信
    public function daijia(){
    	$map['order_id'] = $_REQUEST['id'];
    	$map['status'] = 70;
    	$res = M('order')->save($map);
    	if($res){
    		echo $res;
    	}else{
    		echo 0;
    	}
    }
    
    //保存爱代驾订单信息
    public function savedj(){
    	$data['order_id'] = $_REQUEST['order_id'];
    	$data['adj_id'] = $_REQUEST['id'];
    	$data['type'] = $_REQUEST['type'];
        $data['phone']=$_REQUEST['phone'];
    	$data['create_time'] = time();
    	$res = M('order_adj')->add($data);
    	if($res){
    		echo $res;
    	}else{
    		echo 0;
    	}
    }
}

?>